home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earkit / news / thor / rexx / autoreply.br < prev    next >
Text File  |  1998-05-24  |  6KB  |  176 lines

  1. /* A Thor script to generate an event in reply to  */
  2. /* an email. It should be called from SortMail3    */
  3.  
  4. VerStr = '$VER: AutoReply.br 1.2 (21.08.97) Neil Bothwick'
  5. VerStr = subword(VerStr,2,2)
  6. UrlStr = 'ftp://ftp.aminet.org/pub/aminet/comm/thor/AutoReplyThor.lha'
  7.  
  8. Usage = 'Usage: AutoReply.br Config MessageNo'
  9. options results
  10.  
  11. /* ;;;Strip "'s from arg string and parse into variables */
  12. drop Config.
  13. parse arg CmdLine
  14. CmdLine = compress(CmdLine,'"')
  15. parse var CmdLine Config.Name MsgNum
  16. if Config.Name = '?' | MsgNum = '' then call ExitMsg(Usage)
  17. ;;;
  18. /* ;;;Load bbsread.library if necessary */
  19. if ~show('p', 'BBSREAD') then do
  20.     address command
  21.     'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  22.     'WaitForPort BBSREAD'
  23.     end
  24. ;;;
  25. /* ;;;Open config file and find matching config entry */
  26. if ~open(cfgfile,'ENV:Thor/AutoReply.cfg','r') then call ExitMsg('Failed to open configuration file')
  27. do until eof(cfgfile) | ConfigFound = 'TRUE'
  28.     nextline = readln(cfgfile)
  29.     parse var nextline CfgName CfgVal .
  30.     CfgVal = compress(CfgVal,'"')
  31.     if upper(CfgName) = 'CONFIG' & upper(CfgVal) = upper(Config.Name) then ConfigFound = 'TRUE'
  32.     end
  33.  
  34. if eof(cfgfile) then call ExitMsg('Configuration entry for' Config.Name 'not found')
  35. ;;;
  36. /* ;;;Read configuration details */
  37. n = 0
  38. do until eof(cfgfile)
  39.     nextline = readln(cfgfile)
  40.     parse var nextline CfgName '"' CfgVal '"' .
  41.     CfgVal = compress(CfgVal,'"')
  42.     if upper(CfgName) = 'ENDCONFIG' then leave
  43.     n = n+1
  44.     Config.n.Name = upper(CfgName)
  45.     Config.n.Val  = CfgVal
  46.     end
  47.  
  48. Config.Count = n
  49.  
  50. do i = 1 to Config.Count
  51.     select
  52.         when Config.i.Name = 'SYSTEM'     then Config.System   = Config.i.Val
  53.         when Config.i.Name = 'CONFERENCE' then Config.MailConf = Config.i.Val
  54.         when Config.i.Name = 'SUBJECT'    then Config.Subject  = Config.i.Val
  55.         when Config.i.Name = 'QUOTEMSG'   then Config.QuoteMsg = Config.i.Val
  56.         when Config.i.Name = 'QUOTESTR'   then Config.QuoteStr = Config.i.Val
  57.         when Config.i.Name = 'SIGFILE'    then Config.SigFile  = Config.i.Val
  58.         when Config.i.Name = 'HEADFILE'   then Config.HeadFile = Config.i.Val
  59.         when Config.i.Name = 'TEXTFILE'   then Config.TextFile = Config.i.Val
  60.         when Config.i.Name = 'FOOTFILE'   then Config.FootFile = Config.i.Val
  61.         otherwise call ExitMsg('Configuration file error')
  62.         end
  63.     end
  64.  
  65. if symbol('Config.System')    ~= 'VAR' then call ExitMsg('System name not defined in config')
  66. if symbol('Config.MailConf')  ~= 'VAR' then call ExitMsg('Mail conference not defined in config')
  67. if symbol('Config.TextFile')  ~= 'VAR' then call ExitMsg('Reply text not defined in config')
  68. if symbol('Config.QuoteStr') ~= 'VAR' then Config.QuoteStr = ''
  69. ;;;
  70. /* ;;;Read incoming message */
  71. address BBSREAD
  72. drop MsgBody. MsgHead.
  73. READBRMESSAGE bbsname '"'Config.System'"' confname '"'Config.MailConf'"' msgnr MsgNum textstem MsgBody headstem MsgHead
  74. if RC > 0 then callExitMsg(BBSREAD.LASTERROR)
  75. ;;;
  76. /* ;;;Create message file for reply */
  77. UNIQUEMSGFILE bbsname '"'Config.System'"' stem MsgFile
  78. if ~open(out,MsgFile.NAME,'w') then call ExitMsg('Unable to create message file')
  79. ;;;
  80. /* ;;;Write headers */
  81. headline = 'X-Generator:' VerStr
  82. call writeln(out,headline)
  83. headline = 'X-URL:' UrlStr
  84. call writeln(out,headline)
  85. if symbol('Config.HeadFile') = 'VAR' '' & exists(Config.HeadFile) then do
  86.     if ~open(headers,Config.HeadFile,'R') then call ExitMsg('Unable to open specified header file')
  87.     do until eof(headers)
  88.         headline = readln(headers)
  89.         call writeln(out,headline)
  90.         end
  91.     call close(headers)
  92.     end
  93. if headline > '' then call writeln(out,'')
  94. ;;;
  95. /* ;;;Quote original message above reply */
  96. if upper(Config.QuoteMsg) = 'ABOVE' then do
  97. do i = 1 to MsgBody.TEXT.COUNT
  98.     if length(MsgBody.TEXT.i) > 0 then call writeln(out,Config.QuoteStr||MsgBody.TEXT.i)
  99.     else call writeln(out,'')
  100.     end
  101. end
  102. ;;;
  103. /* ;;;Write reply */
  104. if ~open(reply,Config.TextFile) then call ExitMsg('Unable to open reply text file')
  105. do until eof(reply)
  106.     call writeln(out,readln(reply))
  107.     end
  108. call close(reply)
  109. ;;;
  110. /* ;;;Quote original message below reply */
  111. if upper(Config.QuoteMsg) = 'BELOW' then do i = 1 to MsgBody.TEXT.COUNT
  112.     if length(MsgBody.TEXT.i) > 0 then call writeln(out,Config.QuoteStr||MsgBody.TEXT.i)
  113.     else call writeln(out,'')
  114.     end
  115. ;;;
  116. /* ;;;Add signature */
  117. if symbol('Config.SigFile') = 'VAR' '' & exists(Config.SigFile) then do
  118.     if ~open(sig,Config.SigFile,'R') then call ExitMsg('Unable to open signature file')
  119.     do until eof(sig)
  120.         sigline = readln(sig)
  121.         call writeln(out,sigline)
  122.         end
  123.     call close(sig)
  124.     end
  125. ;;;
  126. /* ;;;Add footer file */
  127. if symbol('Config.FootFile') = 'VAR' '' & exists(Config.FootFile) then do
  128.     if ~open(foot,Config.FootFile,'R') then call ExitMsg('Unable to open footer file')
  129.     do until eof(foot)
  130.         footline = readln(foot)
  131.         call writeln(out,footline)
  132.         end
  133.     call close(foot)
  134.     end
  135. ;;;
  136. call close(out)
  137.  
  138. /* ;;;Create subject line */
  139. ReplySubject = MsgHead.SUBJECT
  140. select
  141.     when symbol('Config.Subject') ~= 'VAR' then do
  142.         if left(upper(ReplySubject),3) ~= 'RE:' then ReplySubject = 'Re:' ReplySubject
  143.         end
  144.     when pos('%S',upper(Config.Subject)) = 0 then ReplySubject = Config.Subject
  145.     otherwise do
  146.         InsertPos = pos('%S',upper(Config.Subject))
  147.         ReplySubject = left(Config.Subject,InsertPos-1)||ReplySubject||substr(Config.Subject,InsertPos+2)
  148.         end
  149.     end
  150. ;;;
  151. /* ;;;Create EMail reply event */
  152. drop EventData.
  153. EventData.TOADDR     = MsgHead.FROMADDR
  154. EventData.SUBJECT    = ReplySubject
  155. EventData.CONFERENCE = Config.MailConf
  156. EventData.MSGFILE    = MsgFile.FILEPART
  157. if symbol('MsgHead.FROMNAME') = 'VAR' then EventData.TONAME = MsgHead.FROMNAME
  158.  
  159. WRITEBREVENT bbsname '"'Config.System'"' event 0 stem EventData
  160. if RC > 0 then call ExitMsg(BBSREAD.LASTERROR)
  161. ;;;
  162. exit
  163.  
  164.  
  165. /* ;;;Exit with a message */
  166. ExitMsg:
  167.     parse arg msgstr
  168.     address command
  169.     if symbol('MsgFile.NAME') = 'VAR' then do
  170.         call close(out)
  171.         'delete >NIL:' MsgFile.NAME
  172.         end
  173.     'RequestChoice >NIL: "AutoReply.br" "'msgstr'" "Bother"'
  174.     exit
  175. ;;;
  176.